package bit_exercises.Day15;

import java.util.Scanner;

/**
 * @author zerorain
 * @date 2022/05/12 15:20
 **/
//第一题  输入数字的二进制1的数量
//public class Main {
//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        while (sc.hasNext()) {
//            int n = sc.nextInt();
//            String str = Integer.toBinaryString(n);
//            char[] c = str.toCharArray();
//            int count = 0;
//            for (int i = 0; i < c.length; i++) {
//                if (c[i] == '1') {
//                    count++;
//                }
//            }
//            System.out.println(count);
//        }
//    }
//}
    //第二题 手套问题
public class Main {
    public int findMinimum(int n, int[] left, int[] right) {
        // write code here
        int LeftSum = 0;
        int RightSum = 0;
        int LeftMin = Integer.MAX_VALUE;
        int RightMin = Integer.MAX_VALUE;
        int a = 0;
        for (int i = 0; i < n; i++) {
            if (left[i] * right[i] == 0) {
                a = a + left[i] + right[i];
            } else {
                LeftSum += left[i];
                if (LeftMin > left[i]) {
                    LeftMin = left[i];
                }
                RightSum += right[i];
                if (RightMin > right[i]) {
                    RightMin = right[i];
                }
            }
        }
        return Math.min(LeftSum - LeftMin +1,RightSum - RightMin +1) + a + 1;
    }
}